<!DOCTYPE html>
<html>

	<head lang="en">
		<meta charset="UTF-8">
		<title>注册</title>
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
		<meta name="format-detection" content="telephone=no">
		<meta name="renderer" content="webkit">
		<meta http-equiv="Cache-Control" content="no-siteapp" />

		<link rel="stylesheet" href="static/css/amazeui.css" />
		<link href="static/css/dlstyle.css" rel="stylesheet" type="text/css">
		
		<link rel="stylesheet" href="static/css/bootstrap.min.css" />
	</head>

	<body>

		<div class="login-boxtitle" style="height: 100px;">
			<div class="logoBig">
				<img src="static/images/logo.png" style="margin-left: 0px ; height: 100px;">
			</div>
		</div>

		<div class="login-banner" style="background: rgb(142,213,21);">
			<div class="login-main">
				<div class="login-banner-bg"><span></span><img width="400"  src="static/images/act2.png" /></div>
				<div class="login-box">

					<h3 class="title">用户注册</h3>

					<div class="clear"></div>

					<div class="login-form" style="background: none;">
						<form>
							<div class="user-name" style="margin-top: 20px;">
								<label for="phoneNumber"><span class="glyphicon glyphicon-phone"
										aria-hidden="true"></span></label>
										<input type="text" name="" id="phoneNumber" placeholder="请输入手机号" style="width: 230px;">
										<button onclick="sendCode()" style="background-color: rgb(162, 227, 228);line-height: 25px;">发送验证码</button>
							</div>
							<div class="user-pass" style="margin-top: 20px;">
								<label for="dynamicCode"><span class="glyphicon glyphicon-flash"
										aria-hidden="true"></span></label>
								<input type="text" name="" id="dynamicCode" placeholder="请输入动态验证码">
							</div>
							<div class="user-pass" style="margin-top: 20px;">
								<label for="password"><span class="glyphicon glyphicon-lock"
										aria-hidden="true"></span></label>
								<input type="text" name="password" id="password" placeholder="请输入密码">
							</div>
						</form>
					</div>
					
					<div class="am-cf">
						<input type="submit" onclick="register()" value="提交注册" class="am-btn am-btn-primary am-btn-sm">
					</div>
					<div class="partner">
						
					</div>

				</div>
			</div>
		</div>

		<div class="footer ">
			<div class="footer-hd ">

			</div>
			<div class="footer-bd ">
				<p>
					<a href="# ">联系我们</a>
					<a href="# ">网站地图</a>
				</p>
			</div>
		</div>
	</body>
<script src="/static/js/axios.min.js"></script>
<script>
	var code;
	function register(){
		var phone = document.getElementById('phoneNumber').value;
		var password = document.getElementById('password').value;
		var code = document.getElementById('dynamicCode').value;
		var user={phone,password,code};
		if (code==this.code){
			axios.post('http://localhost:8080/user/register',user)
		   .then(function (response){
			  console.log(response.data);
			 if (response.data.code==0){
				let jwtToken = response.data.data;
				// 存储token到Local Storage
				localStorage.setItem('token', jwtToken);
				window.history.back();
			 }
			else{
				alert(response.data.msg);
			}			 
		   })
		}
		else{
			alert("验证码错误");
		}
		
	}
	function sendCode(){
		event.preventDefault(); // 阻止默认提交行为
		var phone = document.getElementById('phoneNumber').value;
		var user={phone};
		axios.post('http://localhost:8080/user/sendCodeByRegister',user)
		.then(function (response){
			console.log(response.data);
			self.code=response.data.data;
		})
	}
</script>
</html>